% construct pentadiagonal matrix
function m = pentadiagonal(m,p1,m1,p2,m2,offset,n)

% create template diagonals using shifted eye matrices
diag_main = eye(n);
diag_p1 = [zeros(n,1) diag_main(:,1:n-1)];
diag_m1 = [diag_main(:,2:n) zeros(n,1)];
diag_p2 = [zeros(n,offset) diag_main(:,1:n-offset)];
diag_m2 = [diag_main(:,offset:n) zeros(n,offset-1)];

diag_main_scaled = m .* diag_main;
diag_p1_scaled = p1 .* diag_p1;
diag_m1_scaled = m1 .* diag_m1;
diag_p2_scaled = p2 .* diag_p2;
diag_m2_scaled = m2 .* diag_m2;

m = diag_main_scaled + diag_p1_scaled + diag_m1_scaled;
m = m + diag_p2_scaled + diag_m2_scaled;

